package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.exception.BusinessException;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.UserVocAISituationDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserVocAISituationCommand;
import com.cskaoyan.wordmemorize.service.AIReadService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.val;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Tag(name = "等级-特权管理-AI阅读")
@RestController
@RequestMapping("/admin/voc/ai-read")
public class AIReadController {
    @Resource
    AIReadService aiReadService;
    // 添加AI阅读场景以及选项信息(后台等级特权管理-AI阅读)
    @PostMapping("/situation")
    @OperateLog(dateType = "AI阅读",operateType = 1)
    public Result<String> addAISituation(@RequestBody UserVocAISituationCommand command){
        try {
            aiReadService.addAISituation(command);
            return Result.ok();
        } catch (Exception e) {
            return Result.fail();
        }
    }
    // 更新AI阅读场景以及选项信息(后台等级特权管理-AI阅读)
    @PutMapping("/situation")
    @OperateLog(dateType = "AI阅读",operateType = 2)
    public Result<String> updateAISituation(@RequestBody UserVocAISituationCommand command){
        try {
            aiReadService.updateAISituation(command);
            return Result.ok();
        } catch (Exception e) {
            return Result.fail(e.getMessage());
        }
    }
    // 分页查询AI阅读场景信息(后台等级特权管理-AI阅读)
    @GetMapping("/situation/list")
    public Result<PageDTO<UserVocAISituationDTO>> queryAISituation(PageRequest pageRequest){
        PageDTO<UserVocAISituationDTO> aiSituationList = aiReadService.getAISituationList(pageRequest);
        return Result.ok(aiSituationList);
    }
    // 批量删除AI阅读场景(后台等级特权管理-AI阅读)
    @DeleteMapping("/situation")
    @OperateLog(dateType = "AI阅读",operateType = 4)
    public Result<String> batchDeleteAISituation(@RequestBody BatchDeleteCommand command){
        try {
            List<String> ids = command.getIds();
            List<Long> idList = ids.stream().map(id -> Long.parseLong(id)).collect(Collectors.toList());
            aiReadService.batchDeleteAISituationOption(idList);
            return Result.ok();
        } catch (Exception e) {
            return Result.fail(e.getMessage());
        }

    }
    // 删除AI阅读场景(后台等级特权管理-AI阅读)
    @DeleteMapping("/situation/{id}")
    @OperateLog(dateType = "AI阅读",operateType = 3)
    public Result<String> deleteAISituation(@PathVariable Long id){
        try {
            aiReadService.deleteAISituation(id);
            return Result.ok();
        } catch (BusinessException e) {
            return Result.fail(e.getMessage());
        }
    }
    // 删除AI阅读场景中的某个选项(后台等级特权管理-AI阅读)
    @DeleteMapping("/option/{id}")
    @OperateLog(dateType = "AI阅读",operateType = 3)
    public Result<String> deleteSituationOption(@PathVariable Long id){
        try {
            aiReadService.deleteAISituationOption(id);
            return Result.ok();
        } catch (BusinessException e) {
            return Result.fail(e.getMessage());
        }

    }
}
